package edu.gduf.controller;


import edu.gduf.domain.ResultInfo;
import edu.gduf.service.PictureService;
import edu.gduf.service.impl.infoentry.*;
import edu.gduf.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.List;


/**
 * @author 谢佳豪
 * @data 2020/8/27 - 21:22
 * @target 信息录入模块Controller
 */

@Controller
@RequestMapping("/upload")
@ResponseBody
public class InfoEntryController {

    private StudentClassInfoEntryServiceImpl studentClassInfoEntryService;

    private StudentInfoEntryServiceImpl studentInfoEntryService;

    private ApplicantInfoEntryServiceImpl applicantInfoEntryService;

    private ActivistInfoEntryServiceImpl activistInfoEntryService;

    private InspectorInfoEntryServiceImpl inspectorInfoEntryService;

    private DeveloperInfoEntryServiceImpl developerInfoEntryService;

    private PartyMemberInfoEntryServiceImpl partyMemberInfoEntryService;

    private MarkInfoEntryServiceImpl markInfoEntryService;

    private PictureService pictureService;

    @Autowired
    public void setPictureService(PictureService pictureService) {
        this.pictureService = pictureService;
    }

    @Autowired
    public void setStudentClassInfoEntryService(StudentClassInfoEntryServiceImpl studentClassInfoEntryService) {
        this.studentClassInfoEntryService = studentClassInfoEntryService;
    }

    @Autowired
    public void setStudentInfoEntryService(StudentInfoEntryServiceImpl studentInfoEntryService) {
        this.studentInfoEntryService = studentInfoEntryService;
    }

    @Autowired
    public void setApplicantInfoEntryService(ApplicantInfoEntryServiceImpl applicantInfoEntryService) {
        this.applicantInfoEntryService = applicantInfoEntryService;
    }

    @Autowired
    public void setActivistInfoEntryService(ActivistInfoEntryServiceImpl activistInfoEntryService) {
        this.activistInfoEntryService = activistInfoEntryService;
    }

    @Autowired
    public void setInspectorInfoEntryService(InspectorInfoEntryServiceImpl inspectorInfoEntryService) {
        this.inspectorInfoEntryService = inspectorInfoEntryService;
    }

    @Autowired
    public void setDeveloperInfoEntryService(DeveloperInfoEntryServiceImpl developerInfoEntryService) {
        this.developerInfoEntryService = developerInfoEntryService;
    }

    @Autowired
    public void setPartyMemberInfoEntryService(PartyMemberInfoEntryServiceImpl partyMemberInfoEntryService) {
        this.partyMemberInfoEntryService = partyMemberInfoEntryService;
    }

    @Autowired
    public void setMarkInfoEntryService(MarkInfoEntryServiceImpl markInfoEntryService) {
        this.markInfoEntryService = markInfoEntryService;
    }


    @RequestMapping("/studentClass")
    public ResultInfo studentClass(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String filePath = FileUtil.fileUpload(file, request);
        ResultInfo resultInfo = studentClassInfoEntryService.informationEntry(filePath);
        FileUtil.fileDelete(filePath);
        return resultInfo;
    }

    @RequestMapping("/student")
    public ResultInfo student(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String filePath = FileUtil.fileUpload(file, request);
        ResultInfo resultInfo = studentInfoEntryService.informationEntry(filePath);
        FileUtil.fileDelete(filePath);
        return resultInfo;
    }

    @RequestMapping("/applicant")
    public ResultInfo applicant(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String filePath = FileUtil.fileUpload(file, request);
        ResultInfo resultInfo = applicantInfoEntryService.informationEntry(filePath);
        FileUtil.fileDelete(filePath);
        return resultInfo;
    }

    @RequestMapping("/activist")
    public ResultInfo activist(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String filePath = FileUtil.fileUpload(file, request);
        ResultInfo resultInfo = activistInfoEntryService.informationEntry(filePath);
        FileUtil.fileDelete(filePath);
        return resultInfo;
    }

    @RequestMapping("/inspector")
    public ResultInfo inspector(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String filePath = FileUtil.fileUpload(file, request);
        ResultInfo resultInfo = inspectorInfoEntryService.informationEntry(filePath);
        FileUtil.fileDelete(filePath);
        return resultInfo;
    }

    @RequestMapping("/developer")
    public ResultInfo developer(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String filePath = FileUtil.fileUpload(file, request);
        ResultInfo resultInfo = developerInfoEntryService.informationEntry(filePath);
        FileUtil.fileDelete(filePath);
        return resultInfo;
    }

    @RequestMapping("/partyMember")
    public ResultInfo partyMember(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String filePath = FileUtil.fileUpload(file, request);
        ResultInfo resultInfo = partyMemberInfoEntryService.informationEntry(filePath);
        FileUtil.fileDelete(filePath);
        return resultInfo;
    }

    @RequestMapping("/mark")
    public ResultInfo mark(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String filePath = FileUtil.fileUpload(file, request);
        ResultInfo resultInfo = markInfoEntryService.informationEntry(filePath);
        FileUtil.fileDelete(filePath);
        return resultInfo;
    }

    @RequestMapping("/picture")
    public ResultInfo picture(@RequestParam("file") MultipartFile[] files){
        return pictureService.savePicture(files);
    }
}
